//
//  BackGroudViewController.m
//  制作图标
//
//  Created by mac on 2017/8/23.
//  Copyright © 2017年 yangweiwei. All rights reserved.
//

#import "BackGroudViewController.h"
#import "BackGroundCVCell.h"
#import "SubBeautifyReturnView.h"
@interface BackGroudViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout, SubBeautifyReturnViewDelegate>
@property (nonatomic, strong) SubBeautifyReturnView *navView;
@property (nonatomic, strong) UICollectionView *collectionView;
@end

@implementation BackGroudViewController

static NSString *cellIdentyfier = @"backcell";

- (SubBeautifyReturnView *)navView{
    _navView = [[SubBeautifyReturnView alloc] initWithFrame:CGRectMake(0, 0, KWidth, 64)];
    _navView.delegate = self;
    return _navView;
}
- (void)dismissSuperView{

    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"BackGround";
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.navView];
    //    1.创建布局（横向布局、纵向布局）
   UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
   [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    layout.minimumLineSpacing = 1.0;
  //    2.创建集合视图，设置代理
     self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(self.navView.frame) , KWidth, KHeight - 64) collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
     self.collectionView.dataSource =self;
     self.collectionView.delegate = self;
  //    3.注册单元格（item）
     [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:cellIdentyfier];
  //    4.加载视图
     [self.view addSubview:self.collectionView];
  //      加载nib文件
    [self.collectionView registerNib:[UINib nibWithNibName:@"BackGround" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:cellIdentyfier];
    
    // Do any additional setup after loading the view.
}
#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 30;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    BackGroundCVCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentyfier forIndexPath:indexPath];
    cell.imageView0.image = [UIImage imageNamed:[NSString stringWithFormat:@"skin_%ld",(long)indexPath.row +1]];
    // Configure the cell
    
    return cell;
}
#pragma mark -- UICollectionViewDelegateFlowLayout
/** 每个cell的尺寸*/
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(80, 80);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"skin_%ld",(long)indexPath.row +1 ]];
    if (self.returnValueBlock) {
    
        self.returnValueBlock(image);
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
